package org.flowable;

import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.test.Deployment;
import org.flowable.engine.test.FlowableRule;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.junit.Rule;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * 在测试运行前，会部署与测试类在同一个包下的格式为testClassName.testMethod.bpmn20.xml的资源文件。
 *
 * @Author: LiQiongchao
 * @Date: 2021/8/16 22:08
 */
public class MyBusinessProcessTestWithJunit4 {

    @Rule
    public FlowableRule flowableRule = new FlowableRule();

    @Test
    @Deployment
    public void ruleUsageExample() {
        RuntimeService runtimeService = flowableRule.getRuntimeService();
        runtimeService.startProcessInstanceByKey("holidayRequest");

        TaskService taskService = flowableRule.getTaskService();
        TaskQuery taskQuery = taskService.createTaskQuery();
//        Task task = taskQuery.singleResult();
        List<Task> list = taskQuery.list();
        Task task = list.get(0);
        assertEquals("My Task", task.getName());

        taskService.complete(task.getId());
        assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    }

}
